package a2012c2.t6.chat.client;

import java.awt.Cursor;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;

/**
 * TODO : Description
 * 
 * @author e397496
 * 
 */
public class IconButton extends JButton {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Icon represntativeIcon;

	/**
	 * @param icon
	 */
	public IconButton(Icon icon) {
		this.represntativeIcon = icon;
		this.setIcon(icon);
		this.setFocusable(false);
		this.setSelected(false);
		this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		this.setMargin(new Insets(0, 0, 0, 0));
		this.setContentAreaFilled(false);
		this.addMouseListener(new RollOverListener());
	}

	/**
	 * @return represntativeIcon
	 */
	public Icon getRepresntativeIcon() {
		return represntativeIcon;
	}

	private class RollOverListener extends MouseAdapter {

		public void mouseEntered(MouseEvent e) {
			IconButton b = IconButton.this;
			b.setContentAreaFilled(true);
		}

		public void mouseExited(MouseEvent e) {
			IconButton b = IconButton.this;
			b.setContentAreaFilled(false);
		}
	}
}